﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using game_for_test_helper.src.graphics;
using game_for_test_helper.src.util;

namespace Game_tester_project.temptest
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        string fName;
        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = @"D:\WINXP-BACK\windows system\My Documents\3dsmax\scenes\ChineseDragon\";
            openFileDialog1.Filter = "fbx文件|*.fbx|XML文件|*.xml|所有文件|*.*";
            openFileDialog1.RestoreDirectory = false;
            openFileDialog1.FilterIndex = 1;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                label1.Text = openFileDialog1.SafeFileName;
                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    if (dataGridView1.Rows[i].IsNewRow) break;
                    dataGridView1.Rows.RemoveAt(i--);
                }
                fName = openFileDialog1.FileName;
                filename_t = fName.Replace(".fbx", ".xml");
                filename_t = filename_t.Replace(".FBX", ".xml");



                textBox1.Text = fName;
                openFileDialog1.RestoreDirectory = true;
                if (System.IO.File.Exists(filename_t))
                {
                    System.Console.WriteLine("file exit goood");
                    //label1.Text = "file exit goood";
                    TakeConfigure tcf = (TakeConfigure)SerializeUtil.DeSerilizeAnFileToObject(filename_t, typeof(TakeConfigure));
                    foreach (ModelTakesDefine mtd in tcf.Takelist)
                    {
                        int index1 = dataGridView1.Rows.Add();
                        DataGridViewRow dgvr = dataGridView1.Rows[index1];
                        dgvr.Cells[0].Value = mtd.Clipname;
                        dgvr.Cells[1].Value = mtd.Begin;
                        dgvr.Cells[2].Value = mtd.End;
                        //dataGridView1.Rows.Add(dgvr);
                    }
                    textBox2.Text = tcf.TotalKeyInTake001.ToString();
                } else MessageBox.Show(filename_t);
            } 

        }
        string filename_t;
        private void button2_Click(object sender, EventArgs e)
        {
            List<ModelTakesDefine> list = new List<ModelTakesDefine>();
            ModelTakesDefine mtd;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                try
                {
                    mtd = new ModelTakesDefine();
                    mtd.Clipname = row.Cells[0].Value.ToString();
                    mtd.Begin = int.Parse(row.Cells[1].Value.ToString());
                    mtd.End = int.Parse(row.Cells[2].Value.ToString());
                    //System.Console.WriteLine(mtd.clipname+"  "mtd.Begin+" "+mtd.End);
                    list.Add(mtd);
                }
                catch (System.Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }
            }
            TakeConfigure tcf = new TakeConfigure();
            tcf.Takelist = list;
            tcf.TotalKeyInTake001 = long.Parse(textBox2.Text);
            SerializeUtil.SerilizeAnObject(tcf, filename_t);
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            string values = textBox3.Text;
            float number = float.Parse(values);
            int value1 = (int)(number / 33.33333333);
            textBox4.Text = value1.ToString();
            dataGridView1.CurrentCell.Value = value1;
        }

    }
}
